package hu.dobrosi.dinkycam.j2me.forms;

import hu.dobrosi.dinkycam.j2me.DinkycamApp;
import hu.dobrosi.dinkycam.j2me.Labels;
import hu.dobrosi.util.StringUtil;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextField;

public class LogForm extends DinkycamForm implements CommandListener {
	private Command cmdCapture;

	public LogForm(DinkycamApp app, String title) {
		super(app, title);
	}

	public TextField getLogTextField() {
		return logTextField;
	}

	public void setLogTextField(TextField logTextField) {
		this.logTextField = logTextField;
	}

	private TextField logTextField;
	private Command cmdClear;

	public void buildGUI() {
		super.buildGUI();
		logTextField = new TextField("Log", "", 1024, TextField.ANY);
		StringUtil.logger.println("logger start...");
		append(logTextField);
		cmdClear = new Command(Labels.CLEAR.toString(), Command.EXIT, 1);
		addCommand(cmdClear);
		addCommand(cmdCapture = new Command(Labels.START.toString(),
				Command.ITEM, 100));
		setCommandListener(this);
	}

	public void commandAction(Command c, Displayable s) {
		super.commandAction(c, s);
		if (c.equals(cmdClear)) {
			StringUtil.logger.clear();
		} else if (c == cmdCapture) {
			app.showCapture();
		}
	}
}
